package servlet;

import com.google.gson.Gson;
import dao.CartDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(name = "QueryCardServlet", value = "/QueryCardServlet.s")
public class QueryCartServlet extends HttpServlet {

    private CartDao dao = new CartDao();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        final String name = request.getParameter("name");
        final String uid = request.getParameter("uid");
        List<Map<String, Object>> data = dao.selectCard(name, uid);

        //返回json对象
        Map<String,Object> result = new HashMap<>();
        result.put("data",data);
        final String json = new Gson().toJson(result);
        response.getWriter().append(json);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
